#!/bin/bash
# openoffice.org  headless server script
#
# Author: Raul Suarez rarsa@yahoo.com
#         using example from Simon Eisenmann <si....@struktur.de>
### BEGIN INIT INFO
# Provides:          soffice-headless
# Required-Start:    $local_fs $syslog
# Required-Stop:     $local_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start OpenOffice.org headless server at boot time.
# Description:       Start OpenOffice.org headless server at boot time.
### END INIT INFO
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
DESC="OpenOffice.org headless server" 
NAME=soffice-headless 
DAEMON_HOME=/usr/lib/openoffice/program
DAEMON=$DAEMON_HOME/$NAME.sh 
PIDFILE=/var/run/$NAME.pid 
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed. 
test -x $DAEMON || exit 0

# Read config file if it is present. 
if [ -r /etc/default/$NAME ] 
then
  . /etc/default/$NAME 
fi

# Function that starts the daemon/service.
d_start() { 
  start-stop-daemon --start --pidfile "${PIDFILE}" --chdir "${DAEMON_HOME}" --background --make-pidfile --exec $DAEMON 
}

# Function that stops the daemon/service.
d_stop() { 
  start-stop-daemon --stop --quiet --pidfile "${PIDFILE}" --name java 
  rm -f "${PIDFILE}" 
}

case "$1" in 
  start) 
    echo -n "Starting $DESC: $NAME" 
    d_start 
    echo "." 
    ;; 
  stop) 
    echo -n "Stopping $DESC: $NAME" 
    d_stop 
    echo "." 
    ;; 
  restart|force-reload) 
    echo -n "Restarting $DESC: $NAME" 
    d_stop 
    sleep 1 
    d_start 
    echo "." 
    ;; 
  *) 
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 
    exit 1 
    ;; 
esac

exit 0 

